From 9918d507c372c5777ad00359a8289e6f61ee23db Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Sat, 18 Apr 2020 06:34:39 -0600 Subject: [PATCH] convert subrip, energympro, globalsat_sport to Format class (#542) * convert subrip, energympro, globalsat_sport to Format. * update dependencies in Makefile --- CMakeLists.txt | 3 + GPSBabel.pro | 3 + Makefile.in | 72 +++++++------ energympro.cc | 149 +++----------------------- energympro.h | 182 ++++++++++++++++++++++++++++++++ globalsat_sport.cc | 245 ++++++------------------------------------ globalsat_sport.h | 258 +++++++++++++++++++++++++++++++++++++++++++++ subrip.cc | 71 +++---------- subrip.h | 96 +++++++++++++++++ vecs.h | 12 +-- 10 files changed, 652 insertions(+), 439 deletions(-) create mode 100644 energympro.h create mode 100644 globalsat_sport.h create mode 100644 subrip.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ec463fadd..cb425a433 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,6 +107,7 @@ set(HEADERS cet_util.h csv_util.h defs.h + energympro.h explorist_ini.h filter.h filter_vecs.h @@ -123,6 +124,7 @@ set(HEADERS gbversion.h geojson.h ggv_bin.h + globalsat_sport.h gpx.h grtcirc.h heightgrid.h @@ -158,6 +160,7 @@ set(HEADERS shape.h shapelib/shapefil.h strptime.h + subrip.h units.h vecs.h xcsv.h diff --git a/GPSBabel.pro b/GPSBabel.pro index 3d69f7562..21e85825e 100644 --- a/GPSBabel.pro +++ b/GPSBabel.pro @@ -92,6 +92,7 @@ HEADERS = \ cet_util.h \ csv_util.h \ defs.h \ + energympro.h \ explorist_ini.h \ filter.h \ filter_vecs.h \ @@ -108,6 +109,7 @@ HEADERS = \ gbversion.h \ geojson.h \ ggv_bin.h \ + globalsat_sport.h \ gpx.h \ grtcirc.h \ heightgrid.h \ @@ -143,6 +145,7 @@ HEADERS = \ shape.h \ shapelib/shapefil.h \ strptime.h \ + subrip.h \ units.h \ vecs.h \ xcsv.h \ diff --git a/Makefile.in b/Makefile.in index a7053b6be..03de36ec2 100644 --- a/Makefile.in +++ b/Makefile.in @@ -488,7 +488,7 @@ easygps.o: easygps.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \ inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h energympro.o: energympro.cc defs.h config.h zlib/zlib.h zlib/zconf.h \ formspec.h inifile.h gbfile.h session.h src/core/datetime.h \ - src/core/optional.h + src/core/optional.h energympro.h format.h enigma.o: enigma.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \ inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h exif.o: exif.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \ @@ -508,14 +508,14 @@ filter_vecs.o: filter_vecs.cc defs.h config.h zlib/zlib.h zlib/zconf.h \ duplicate.h height.h heightgrid.h interpolate.h nukedata.h polygon.h \ position.h radius.h reverse_route.h smplrout.h sort.h stackfilter.h \ swapdata.h trackfilter.h transform.h validate.h gbversion.h vecs.h \ - format.h geojson.h src/core/file.h ggv_bin.h gpx.h \ - src/core/xmlstreamwriter.h src/core/xmltag.h legacyformat.h \ - lowranceusr.h mynav.h nmea.h random.h shape.h shapelib/shapefil.h \ - xcsv.h garmin_fs.h jeeps/gps.h jeeps/../defs.h jeeps/gpsport.h \ - jeeps/gpsdevice.h jeeps/gpssend.h jeeps/gpsread.h jeeps/gpsutil.h \ - jeeps/gpsapp.h jeeps/gpsprot.h jeeps/gpscom.h jeeps/gpsfmt.h \ - jeeps/gpsmath.h jeeps/gpsmem.h jeeps/gpsrqst.h src/core/textstream.h \ - yahoo.h xmlgeneric.h + format.h energympro.h geojson.h src/core/file.h ggv_bin.h \ + globalsat_sport.h gpx.h src/core/xmlstreamwriter.h src/core/xmltag.h \ + legacyformat.h lowranceusr.h mynav.h qstarz_bl_1000.h nmea.h random.h \ + shape.h shapelib/shapefil.h subrip.h xcsv.h garmin_fs.h jeeps/gps.h \ + jeeps/../defs.h jeeps/gpsport.h jeeps/gpsdevice.h jeeps/gpssend.h \ + jeeps/gpsread.h jeeps/gpsutil.h jeeps/gpsapp.h jeeps/gpsprot.h \ + jeeps/gpscom.h jeeps/gpsfmt.h jeeps/gpsmath.h jeeps/gpsmem.h \ + jeeps/gpsrqst.h src/core/textstream.h yahoo.h xmlgeneric.h formspec.o: formspec.cc defs.h config.h zlib/zlib.h zlib/zconf.h \ formspec.h inifile.h gbfile.h session.h src/core/datetime.h \ src/core/optional.h @@ -533,9 +533,10 @@ garmin.o: garmin.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \ jeeps/gpsread.h jeeps/gpsutil.h jeeps/gpsapp.h jeeps/gpsprot.h \ jeeps/gpscom.h jeeps/gpsfmt.h jeeps/gpsmath.h jeeps/gpsmem.h \ jeeps/gpsrqst.h garmin_tables.h grtcirc.h jeeps/gpsserial.h vecs.h \ - geojson.h src/core/file.h ggv_bin.h gpx.h src/core/xmlstreamwriter.h \ - src/core/xmltag.h legacyformat.h lowranceusr.h mynav.h nmea.h random.h \ - shape.h shapelib/shapefil.h xcsv.h src/core/textstream.h yahoo.h \ + energympro.h geojson.h src/core/file.h ggv_bin.h globalsat_sport.h \ + gpx.h src/core/xmlstreamwriter.h src/core/xmltag.h legacyformat.h \ + lowranceusr.h mynav.h qstarz_bl_1000.h nmea.h random.h shape.h \ + shapelib/shapefil.h subrip.h xcsv.h src/core/textstream.h yahoo.h \ xmlgeneric.h garmin_device_xml.o: garmin_device_xml.cc defs.h config.h zlib/zlib.h \ zlib/zconf.h formspec.h inifile.h gbfile.h session.h \ @@ -609,7 +610,8 @@ globals.o: globals.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \ gbversion.h globalsat_sport.o: globalsat_sport.cc defs.h config.h zlib/zlib.h \ zlib/zconf.h formspec.h inifile.h gbfile.h session.h \ - src/core/datetime.h src/core/optional.h gbser.h + src/core/datetime.h src/core/optional.h globalsat_sport.h format.h \ + gbser.h glogbook.o: glogbook.cc defs.h config.h zlib/zlib.h zlib/zconf.h \ formspec.h inifile.h gbfile.h session.h src/core/datetime.h \ src/core/optional.h src/core/file.h xmlgeneric.h @@ -817,9 +819,10 @@ maggeo.o: maggeo.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \ magproto.o: magproto.cc defs.h config.h zlib/zlib.h zlib/zconf.h \ formspec.h inifile.h gbfile.h session.h src/core/datetime.h \ src/core/optional.h explorist_ini.h format.h gbser.h magellan.h vecs.h \ - geojson.h src/core/file.h ggv_bin.h gpx.h src/core/xmlstreamwriter.h \ - src/core/xmltag.h legacyformat.h lowranceusr.h mynav.h nmea.h random.h \ - shape.h shapelib/shapefil.h xcsv.h garmin_fs.h jeeps/gps.h \ + energympro.h geojson.h src/core/file.h ggv_bin.h globalsat_sport.h \ + gpx.h src/core/xmlstreamwriter.h src/core/xmltag.h legacyformat.h \ + lowranceusr.h mynav.h qstarz_bl_1000.h nmea.h random.h shape.h \ + shapelib/shapefil.h subrip.h xcsv.h garmin_fs.h jeeps/gps.h \ jeeps/../defs.h jeeps/gpsport.h jeeps/gpsdevice.h jeeps/gpssend.h \ jeeps/gpsread.h jeeps/gpsutil.h jeeps/gpsapp.h jeeps/gpsprot.h \ jeeps/gpscom.h jeeps/gpsfmt.h jeeps/gpsmath.h jeeps/gpsmem.h \ @@ -830,9 +833,10 @@ main.o: main.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \ discard.h duplicate.h height.h heightgrid.h interpolate.h nukedata.h \ polygon.h position.h radius.h reverse_route.h smplrout.h sort.h \ stackfilter.h swapdata.h trackfilter.h transform.h validate.h format.h \ - src/core/file.h src/core/usasciicodec.h vecs.h geojson.h ggv_bin.h \ - gpx.h src/core/xmlstreamwriter.h src/core/xmltag.h legacyformat.h \ - lowranceusr.h mynav.h nmea.h random.h shape.h shapelib/shapefil.h \ + src/core/file.h src/core/usasciicodec.h vecs.h energympro.h geojson.h \ + ggv_bin.h globalsat_sport.h gpx.h src/core/xmlstreamwriter.h \ + src/core/xmltag.h legacyformat.h lowranceusr.h mynav.h \ + qstarz_bl_1000.h nmea.h random.h shape.h shapelib/shapefil.h subrip.h \ xcsv.h garmin_fs.h jeeps/gps.h jeeps/../defs.h jeeps/gpsport.h \ jeeps/gpsdevice.h jeeps/gpssend.h jeeps/gpsread.h jeeps/gpsutil.h \ jeeps/gpsapp.h jeeps/gpsprot.h jeeps/gpscom.h jeeps/gpsfmt.h \ @@ -922,9 +926,9 @@ position.o: position.cc defs.h config.h zlib/zlib.h zlib/zconf.h \ psitrex.o: psitrex.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \ inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h \ garmin_tables.h -qstarz_bl_1000.o: qstarz_bl_1000.cc defs.h config.h zlib/zlib.h zlib/zconf.h \ - formspec.h inifile.h gbfile.h session.h src/core/datetime.h \ - src/core/optional.h format.h +qstarz_bl_1000.o: qstarz_bl_1000.cc qstarz_bl_1000.h defs.h config.h \ + zlib/zlib.h zlib/zconf.h formspec.h inifile.h gbfile.h session.h \ + src/core/datetime.h src/core/optional.h format.h src/core/logging.h radius.o: radius.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \ inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h \ radius.h filter.h grtcirc.h @@ -994,7 +998,8 @@ stmwpp.o: stmwpp.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \ csv_util.h cet_util.h strptime.o: strptime.c config.h strptime.h subrip.o: subrip.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \ - inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h + inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h \ + subrip.h format.h src/core/logging.h swapdata.o: swapdata.cc defs.h config.h zlib/zlib.h zlib/zconf.h \ formspec.h inifile.h gbfile.h session.h src/core/datetime.h \ src/core/optional.h swapdata.h filter.h @@ -1039,7 +1044,7 @@ units.o: units.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \ units.h util.o: util.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \ inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h \ - cet.h src/core/xmltag.h + cet.h src/core/logging.h src/core/xmltag.h util_crc.o: util_crc.cc v900.o: v900.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \ inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h @@ -1051,14 +1056,15 @@ vcf.o: vcf.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \ jeeps/gpsmath.h jeeps/gpsport.h vecs.o: vecs.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \ inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h \ - vecs.h format.h geojson.h src/core/file.h ggv_bin.h gpx.h \ - src/core/xmlstreamwriter.h src/core/xmltag.h legacyformat.h \ - lowranceusr.h mynav.h nmea.h random.h shape.h shapelib/shapefil.h \ - xcsv.h garmin_fs.h jeeps/gps.h jeeps/../defs.h jeeps/gpsport.h \ - jeeps/gpsdevice.h jeeps/gpssend.h jeeps/gpsread.h jeeps/gpsutil.h \ - jeeps/gpsapp.h jeeps/gpsprot.h jeeps/gpscom.h jeeps/gpsfmt.h \ - jeeps/gpsmath.h jeeps/gpsmem.h jeeps/gpsrqst.h src/core/textstream.h \ - yahoo.h xmlgeneric.h gbversion.h src/core/logging.h + vecs.h format.h energympro.h geojson.h src/core/file.h ggv_bin.h \ + globalsat_sport.h gpx.h src/core/xmlstreamwriter.h src/core/xmltag.h \ + legacyformat.h lowranceusr.h mynav.h qstarz_bl_1000.h nmea.h random.h \ + shape.h shapelib/shapefil.h subrip.h xcsv.h garmin_fs.h jeeps/gps.h \ + jeeps/../defs.h jeeps/gpsport.h jeeps/gpsdevice.h jeeps/gpssend.h \ + jeeps/gpsread.h jeeps/gpsutil.h jeeps/gpsapp.h jeeps/gpsprot.h \ + jeeps/gpscom.h jeeps/gpsfmt.h jeeps/gpsmath.h jeeps/gpsmem.h \ + jeeps/gpsrqst.h src/core/textstream.h yahoo.h xmlgeneric.h gbversion.h \ + src/core/logging.h vidaone.o: vidaone.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \ inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h vitosmt.o: vitosmt.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \ @@ -1094,7 +1100,7 @@ xcsv.o: xcsv.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \ xcsv.h format.h xcsv_tokens.gperf xmlgeneric.o: xmlgeneric.cc defs.h config.h zlib/zlib.h zlib/zconf.h \ formspec.h inifile.h gbfile.h session.h src/core/datetime.h \ - src/core/optional.h cet_util.h src/core/file.h xmlgeneric.h + src/core/optional.h xmlgeneric.h src/core/file.h xmltag.o: xmltag.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \ inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h \ src/core/xmltag.h diff --git a/energympro.cc b/energympro.cc index 2f881c516..ddb3269b8 100644 --- a/energympro.cc +++ b/energympro.cc @@ -20,7 +20,7 @@ */ -#include +#include // for int32_t #include // for printf, SEEK_SET, SEEK_CUR, SEEK_END #include // for QDate @@ -32,118 +32,18 @@ #include // for UTC #include "defs.h" +#include "energympro.h" #include "gbfile.h" // for gbfgetc, gbfseek, gbfclose, gbfopen, gbfread, gbfgetuint32, gbfcopyfrom, gbfgetuint16, gbfile, gbsize_t #include "src/core/datetime.h" // for DateTime #define MYNAME "energympro" -static gbfile* file_in; - -struct tw_date { - uint8_t Year; - uint8_t Month; - uint8_t Day; -}; - -struct tw_time { - uint8_t Hour; - uint8_t Minute; - uint8_t Second; -}; - -struct tw_workout { - tw_date dateStart; // start date - tw_time timeStart; // start time - uint16_t TotalRecPt; // Total record Point - uint32_t TotalTime; // Total Time - uint32_t TotalDist; // Total Distance - uint16_t LapNumber; // Lap Number - uint16_t Calory; // Calory - uint32_t MaxSpeed; // Max Speed - uint32_t AvgSpeed; // average Speed - uint8_t MaxHeart; // Max Heartrate - uint8_t AvgHeart; // average Heart - uint16_t Ascent; // Ascent - uint16_t Descent; // Descent - int16_t MinAlti; // Min Altitude - int16_t MaxAlti; // Max Altitude - uint8_t AvgCad; // average Cadence - uint8_t MaxCad; // Best Cadence - uint16_t AvgPower; // average Power - uint16_t MaxPower; // Max Power - char VersionProduct[15]; - uint8_t reserved1; - uint8_t VersionVerNum; - uint8_t reserved2[17]; -}; - - -struct tw_point { - uint32_t Latitude; - uint32_t Longitude; - int16_t Altitude; - uint16_t reserved1; - uint32_t Speed; - uint16_t IntervalDist; // Interval Distance - uint16_t reserved2; - uint32_t lntervalTime; // Interval time - uint8_t Status; //Status (0 = ok, 1 = miss, 2 = no good, 3 = bad) - uint8_t HR_Heartrate; - uint8_t HR_Status; - uint8_t reserved3; - uint32_t Speed_Speed; - uint8_t Speed_Status; - uint8_t reserved4; - uint8_t reserved5; - uint8_t reserved6; - uint8_t Cadence_Cadence; - uint8_t Cadence_Status; - uint16_t Power_Cadence; - uint16_t Power_Power; - uint8_t Power_Status; - uint8_t reserved7; - uint8_t Temp; - uint8_t reserved8; - uint8_t reserved9; - uint8_t reserved10; -}; - -struct tw_lap { - uint32_t splitTime; // split time - uint32_t TotalTime; // Total Time - uint16_t Number; // Number - uint16_t reserved1; - uint32_t lDistance; // Distance - uint16_t Calorie; // Calorie - uint16_t reserved2; - uint32_t MaxSpeed; // Max Speed - uint32_t AvgSpeed; // average Speed - uint8_t MaxHeartrate; // Max Heartrate - uint8_t AvgHeartrate; // average Heartrate - int16_t MinAlti; // Min Altitude - int16_t MaxAlti; // Max Altitude - uint8_t AvgCad; // average Cadence - uint8_t MaxCad; // Max Cadence - uint16_t AvgPower; // average Power - uint16_t MaxPower; // Max Power - uint16_t StartRecPt; // start record point - uint16_t FinishRecPt; // Finish record point -}; - -static char* opt_timezone = nullptr; -static QTimeZone* timezn = nullptr; - -static -QVector energympro_args = { - {"timezone", &opt_timezone, "Time zone ID", nullptr, ARGTYPE_STRING, ARG_NOMINMAX, nullptr}, -}; - //******************************************************************************* // local helper functions //******************************************************************************* -static void -read_point(route_head* gpsbabel_route,gpsbabel::DateTime& gpsDateTime) +void +EnergymproFormat::read_point(route_head* gpsbabel_route,gpsbabel::DateTime& gpsDateTime) const { tw_point point{}; gbfread(&point,sizeof(tw_point),1,file_in); @@ -191,8 +91,8 @@ read_point(route_head* gpsbabel_route,gpsbabel::DateTime& gpsDateTime) } -static void -read_lap() +void +EnergymproFormat::read_lap() const { tw_lap lap{}; gbfread(&lap,sizeof(tw_lap),1,file_in); @@ -211,8 +111,8 @@ read_lap() // global callbacks called by gpsbabel main process //******************************************************************************* -static void -rd_init(const QString& fname) +void +EnergymproFormat::rd_init(const QString& fname) { if (global_opts.debug_level > 1) { printf(MYNAME " rd_deinit()\n"); @@ -238,8 +138,8 @@ rd_init(const QString& fname) } } -static void -rd_deinit() +void +EnergymproFormat::rd_deinit() { if (timezn != nullptr) { delete timezn; @@ -251,8 +151,8 @@ rd_deinit() gbfclose(file_in); } -static void -track_read() +void +EnergymproFormat::track_read() { if (global_opts.debug_level > 1) { printf(MYNAME " waypoint_read()\n"); @@ -310,8 +210,8 @@ track_read() } } -static void -data_read() +void +EnergymproFormat::read() { if (global_opts.debug_level > 1) { printf(MYNAME " data_read()\n"); @@ -319,24 +219,3 @@ data_read() track_read(); } - - -ff_vecs_t energympro_vecs = { - ff_type_file, - { - ff_cap_none, // waypoints - ff_cap_read, // tracks - ff_cap_none // routes - }, - rd_init, // rd_init - nullptr, // wr_init - rd_deinit, // rd_deinit - nullptr, // wr_deinit - data_read, // read - nullptr, // write - nullptr, // exit - &energympro_args, // args - CET_CHARSET_ASCII, 0, // encode, fixed_encode - NULL_POS_OPS, - nullptr -}; diff --git a/energympro.h b/energympro.h new file mode 100644 index 000000000..18403fb1d --- /dev/null +++ b/energympro.h @@ -0,0 +1,182 @@ +/* + Handle energympro (GPS training watch) .cpo files + + Copyright (c) 2014 Zingo Andersen zingo@vectrace.com + Copyright (C) 2014 Robert Lipe, robertlipe+source@gpsbabel.org + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + */ +#ifndef ENERGYMPRO_H_INCLUDED_ +#define ENERGYMPRO_H_INCLUDED_ + +#include // for uint8_t, uint16_t, uint32_t, int16_t + +#include // for QString +#include // for QTimeZone +#include // for QVector + +#include "defs.h" +#include "format.h" // for Format +#include "gbfile.h" // for gbfgetc, gbfseek, gbfclose, gbfopen, gbfread, gbfgetuint32, gbfcopyfrom, gbfgetuint16, gbfile, gbsize_t +#include "src/core/datetime.h" // for DateTime + + +class EnergymproFormat : public Format +{ +public: + QVector* get_args() override + { + return &energympro_args; + } + + ff_type get_type() const override + { + return ff_type_file; + } + + QVector get_cap() const override + { + return { + ff_cap_none, // waypoints + ff_cap_read, // tracks + ff_cap_none // routes + }; + } + + QString get_encode() const override + { + return CET_CHARSET_ASCII; + } + + int get_fixed_encode() const override + { + return 0; + } + + void rd_init(const QString& fname) override; + void read() override; + void rd_deinit() override; + +private: + /* Types */ + + struct tw_date { + uint8_t Year; + uint8_t Month; + uint8_t Day; + }; + + struct tw_time { + uint8_t Hour; + uint8_t Minute; + uint8_t Second; + }; + + struct tw_workout { + tw_date dateStart; // start date + tw_time timeStart; // start time + uint16_t TotalRecPt; // Total record Point + uint32_t TotalTime; // Total Time + uint32_t TotalDist; // Total Distance + uint16_t LapNumber; // Lap Number + uint16_t Calory; // Calory + uint32_t MaxSpeed; // Max Speed + uint32_t AvgSpeed; // average Speed + uint8_t MaxHeart; // Max Heartrate + uint8_t AvgHeart; // average Heart + uint16_t Ascent; // Ascent + uint16_t Descent; // Descent + int16_t MinAlti; // Min Altitude + int16_t MaxAlti; // Max Altitude + uint8_t AvgCad; // average Cadence + uint8_t MaxCad; // Best Cadence + uint16_t AvgPower; // average Power + uint16_t MaxPower; // Max Power + char VersionProduct[15]; + uint8_t reserved1; + uint8_t VersionVerNum; + uint8_t reserved2[17]; + }; + + struct tw_point { + uint32_t Latitude; + uint32_t Longitude; + int16_t Altitude; + uint16_t reserved1; + uint32_t Speed; + uint16_t IntervalDist; // Interval Distance + uint16_t reserved2; + uint32_t lntervalTime; // Interval time + uint8_t Status; //Status (0 = ok, 1 = miss, 2 = no good, 3 = bad) + uint8_t HR_Heartrate; + uint8_t HR_Status; + uint8_t reserved3; + uint32_t Speed_Speed; + uint8_t Speed_Status; + uint8_t reserved4; + uint8_t reserved5; + uint8_t reserved6; + uint8_t Cadence_Cadence; + uint8_t Cadence_Status; + uint16_t Power_Cadence; + uint16_t Power_Power; + uint8_t Power_Status; + uint8_t reserved7; + uint8_t Temp; + uint8_t reserved8; + uint8_t reserved9; + uint8_t reserved10; + }; + + struct tw_lap { + uint32_t splitTime; // split time + uint32_t TotalTime; // Total Time + uint16_t Number; // Number + uint16_t reserved1; + uint32_t lDistance; // Distance + uint16_t Calorie; // Calorie + uint16_t reserved2; + uint32_t MaxSpeed; // Max Speed + uint32_t AvgSpeed; // average Speed + uint8_t MaxHeartrate; // Max Heartrate + uint8_t AvgHeartrate; // average Heartrate + int16_t MinAlti; // Min Altitude + int16_t MaxAlti; // Max Altitude + uint8_t AvgCad; // average Cadence + uint8_t MaxCad; // Max Cadence + uint16_t AvgPower; // average Power + uint16_t MaxPower; // Max Power + uint16_t StartRecPt; // start record point + uint16_t FinishRecPt; // Finish record point + }; + + /* Member Functions */ + + void read_point(route_head* gpsbabel_route, gpsbabel::DateTime& gpsDateTime) const; + void read_lap() const; + void track_read(); + + /* Data Members */ + + gbfile* file_in{nullptr}; + char* opt_timezone{nullptr}; + QTimeZone* timezn{nullptr}; + + QVector energympro_args = { + {"timezone", &opt_timezone, "Time zone ID", nullptr, ARGTYPE_STRING, ARG_NOMINMAX, nullptr}, + }; +}; +#endif // ENERGYMPRO_H_INCLUDED_ diff --git a/globalsat_sport.cc b/globalsat_sport.cc index 8d0e6cf10..34c36e4da 100644 --- a/globalsat_sport.cc +++ b/globalsat_sport.cc @@ -45,173 +45,20 @@ #include // for QString #include // for QTime #include // for QTimeZone -#include // for QVector #include // for LocalTime #include // for qPrintable #include "defs.h" +#include "globalsat_sport.h" #include "gbfile.h" // for gbfclose, gbfopen, gbfread, gbfwrite, gbfile #include "gbser.h" // for gbser_deinit, gbser_flush, gbser_init, gbser_readc_wait, gbser_set_speed, gbser_writec, gbser_ERROR, gbser_NOTHING, gbser_OK #include "src/core/datetime.h" // for DateTime - #define MYNAME "GlobalsatSport" -static void* serial_handle; -static bool isSizeSwapped; - -static char* showlist = nullptr; // if true show a list instead of download tracks -static char* track = nullptr; // if not 0 only download this track, if 0 download all - -static char* opt_dump_file = nullptr; // dump raw data to this file (optional) -static char* opt_input_dump_file = nullptr; // if true input is from a dump-file instead of serial console -static char* opt_timezone = nullptr; -static gbfile* dumpfile = nullptr; // used for creating bin/RAW datadump files, useful for testing -static gbfile* in_file = nullptr; // used for reading from bin/RAW datadump files, useful for testing -static QTimeZone* timezn = nullptr; - -static -QVector globalsat_args = { - {"showlist", &showlist, "list tracks", nullptr, ARGTYPE_BOOL, ARG_NOMINMAX, nullptr}, - {"track", &track, "get track", "0", ARGTYPE_INT, ARG_NOMINMAX, nullptr}, - {"dump-file", &opt_dump_file, "Dump raw data to this file", nullptr, ARGTYPE_OUTFILE, ARG_NOMINMAX, nullptr}, - {"input-is-dump-file", &opt_input_dump_file, "Dump raw data to this file", nullptr, ARGTYPE_BOOL, ARG_NOMINMAX, nullptr}, - {"timezone", &opt_timezone, "Time zone ID", nullptr, ARGTYPE_STRING, ARG_NOMINMAX, nullptr}, -}; - -enum globalsat_commands_e { - CommandWhoAmI = 0xBF, - CommandGetSystemInformation = 0x85, - CommandGetSystemConfiguration = 0x86, - - CommandSetSystemConfiguration = 0x96, - CommandSetSystemInformation = 0x98, - CommandGetScreenshot = 0x83, - - CommandGetWaypoints = 0x77, - CommandSendWaypoint = 0x76, - CommandDeleteWaypoints = 0x75, - - CommandSendRoute = 0x93, - CommandDeleteAllRoutes = 0x97, - - CommandGetTrackFileHeaders = 0x78, - CommandGetTrackFileSections = 0x80, - CommandGetNextTrackSection = 0x81, - //CommandReGetLastSection = 0x82, - CommandId_FINISH = 0x8A, - CommandSendTrackStart = 0x90, - CommandSendTrackSection = 0x91, - - HeaderTypeLaps = 0xAA, - HeaderTypeTrackPoints = 0x55, - - ResponseInsufficientMemory = 0x95, - ResponseResendTrackSection = 0x92, - ResponseSendTrackFinish = 0x9A -}; - -struct gh_date { - uint8_t Year; - uint8_t Month; - uint8_t Day; -}; - -struct gh_time { - uint8_t Hour; - uint8_t Minute; - uint8_t Second; -}; - -struct gh_trainheader { - gh_date dateStart; - gh_time timeStart; - uint32_t TotalPoint; //6-9 - uint32_t TotalTime; //10-13 - uint32_t TotalDistance; //14-17 - uint16_t LapCnts; //18-19 - union { - uint32_t Index; - uint32_t StartPt; - } gh_ptrec; //20-23 - union { - uint32_t LapIndex; - uint32_t EndPt; - } gh_laprec; //24-27 - uint8_t DataType; //28 -}; - -struct gh_db_train { - gh_date dateStart; - gh_time timeStart; - uint32_t TotalPoint; //6-9 - uint32_t TotalTime; //10-13 - uint32_t TotalDistance; //14-17 - uint16_t LapCnts; //18-19 - union { - uint32_t Index; - uint32_t StartPt; - } gh_ptrec; //20-23 - union { - uint32_t LapIndex; - uint32_t EndPt; - } gh_laprec; //24-27 - uint8_t MultiSport; //28 on/off - uint16_t Calory; //29-30 - uint32_t MaxSpeed; - uint8_t MaxHeart; - uint8_t AvgHeart; - - uint16_t Ascent; - uint16_t Descent; - - int16_t MinAlti; - int16_t MaxAlti; - uint16_t AvgCadns; - uint16_t BestCadns; - uint16_t AvgPower; - uint16_t MaxPower; - uint8_t Sport1; - uint8_t Sport2; - uint8_t Sport3; - uint8_t Sport4; - uint8_t Sport5; -}; - -struct gh_db_lap { - uint32_t AccruedTime; - uint32_t TotalTime; - uint32_t TotalDistance; - uint16_t Calory; - uint32_t MaxSpeed; - uint8_t MaxHeart; - uint8_t AvgHeart; - int16_t MinAlti; - int16_t MaxAlti; - uint16_t AvgCadns; - uint16_t BestCadns; - uint16_t AvgPower; - uint16_t MaxPower; - uint8_t MultiSportIndex; - uint32_t StartPt; - uint32_t EndPt; -}; - -struct gh_recpoint { - uint32_t Latitude; - uint32_t Longitude; - int16_t Altitude; - uint32_t Speed; - uint8_t HeartRate; - uint32_t IntervalTime; - uint16_t Cadence; - uint16_t PwrCadence; - uint16_t Power; -}; - -static void -serial_init(const char* fname) +void +GlobalsatSportFormat::serial_init(const char* fname) { if (serial_handle = gbser_init(fname), nullptr == serial_handle) { fatal(MYNAME ": Can't open port '%s'\n", fname); @@ -223,8 +70,8 @@ serial_init(const char* fname) gbser_flush(serial_handle); } -static void -serial_deinit() +void +GlobalsatSportFormat::serial_deinit() { if (global_opts.debug_level > 1) { printf(MYNAME " serial_deinit()\n"); @@ -236,8 +83,8 @@ serial_deinit() } } -static int -serial_recv_byte() +int +GlobalsatSportFormat::serial_recv_byte() const { /* allow for a delay of 4s */ int result = gbser_readc_wait(serial_handle, 4000); @@ -252,8 +99,8 @@ serial_recv_byte() return result; } -static void -serial_write_byte(uint8_t byte) +void +GlobalsatSportFormat::serial_write_byte(uint8_t byte) const { if (global_opts.debug_level > 1) { printf("0x%02x (%d), ", byte, byte); @@ -265,8 +112,8 @@ serial_write_byte(uint8_t byte) } } -static int -recv_byte() +int +GlobalsatSportFormat::recv_byte() { int result=0; // Read from serial or dumpfile @@ -283,8 +130,8 @@ recv_byte() return result; } -static void -write_byte(uint8_t byte) +void +GlobalsatSportFormat::write_byte(uint8_t byte) { // Write serial or not at all if input is a dumpfile if (!opt_input_dump_file) { @@ -297,8 +144,8 @@ write_byte(uint8_t byte) } -static void -globalsat_write_package(uint8_t* payload, uint32_t size) +void +GlobalsatSportFormat::globalsat_write_package(uint8_t* payload, uint32_t size) { //All globalsat devices but gh561 //2 @@ -332,8 +179,8 @@ globalsat_write_package(uint8_t* payload, uint32_t size) } } -static uint8_t* -globalsat_read_package(int* out_length, uint8_t* out_DeviceCommand) +uint8_t* +GlobalsatSportFormat::globalsat_read_package(int* out_length, uint8_t* out_DeviceCommand) { uint8_t crc; uint8_t calc_crc = 0; @@ -381,16 +228,16 @@ error_out: /* * Send one byte package */ -static void -globalsat_send_simple(uint8_t command) +void +GlobalsatSportFormat::globalsat_send_simple(uint8_t command) { uint8_t payload[1]; payload[0] = command; globalsat_write_package(payload, 1); } -static void -globalsat_probe_device() +void +GlobalsatSportFormat::globalsat_probe_device() { //TODO try this first if fails try with false, to support 561 isSizeSwapped = false; //all devices but gh561 since gh561 has swapped size. @@ -412,8 +259,8 @@ globalsat_probe_device() } } -static void -rd_init(const QString& fname) +void +GlobalsatSportFormat::rd_init(const QString& fname) { if (global_opts.debug_level > 1) { printf(MYNAME " rd_init()\n"); @@ -449,8 +296,8 @@ rd_init(const QString& fname) globalsat_probe_device(); } -static void -rd_deinit() +void +GlobalsatSportFormat::rd_deinit() { if (global_opts.debug_level > 1) { printf(MYNAME " rd_deinit()\n"); @@ -475,10 +322,8 @@ rd_deinit() } } -static void track_read(); - -static void -waypoint_read() +void +GlobalsatSportFormat::waypoint_read() { if (global_opts.debug_level > 1) { printf(MYNAME " waypoint_read()\n"); @@ -500,8 +345,8 @@ waypoint_read() track_read(); } -static void -track_read() +void +GlobalsatSportFormat::track_read() { if (global_opts.debug_level > 1) { printf(MYNAME " track_read()\n"); @@ -812,19 +657,19 @@ track_read() } } -static void -route_read() +void +GlobalsatSportFormat::route_read() { if (global_opts.debug_level > 1) { printf(MYNAME " route_read() TODO\n"); } } -static void -data_read() +void +GlobalsatSportFormat::read() { if (global_opts.debug_level > 1) { - printf(MYNAME " data_read()\n"); + printf(MYNAME " read()\n"); } if (global_opts.masked_objective & WPTDATAMASK) { @@ -841,25 +686,3 @@ data_read() fatal(MYNAME ": Nothing to do.\n"); } } - -// This used the serial communication to the watch -ff_vecs_t globalsat_sport_vecs = { - ff_type_serial, // type - { - ff_cap_none, // waypoints - ff_cap_read, // tracks - ff_cap_none, // routes - }, - rd_init, // rd_init - nullptr, // wr_init - rd_deinit, // rd_deinit - nullptr, // wr_deinit - data_read, // read - nullptr, // write - nullptr, // exit - &globalsat_args, // args - CET_CHARSET_ASCII, // encode - 0, // fixed_encode - NULL_POS_OPS, // position_ops - nullptr -}; diff --git a/globalsat_sport.h b/globalsat_sport.h new file mode 100644 index 000000000..2b02a49c5 --- /dev/null +++ b/globalsat_sport.h @@ -0,0 +1,258 @@ +/* + Global data for GPSBabel. + + Copyright (C) 2012-2016, Zingo Andersen zingo@zingo.org + Copyright (C) 2016 Robert Lipe, robertlipe+source@gpsbabel.org + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + */ +/* + * This is the bridge between the GPSBabel and globalsat sport devices + * gh625XT. Globalsat has a few devices under the sport brand and they + * are using a similar USB serial protocol. + * Currently only gh625XT is supported by this driver but the code could + * extended (maybe autodetect) support more devices in the future. + * + * The code is based on GH625XT-COMMUNICATION_SPECS_20111205-1.pdf from Globasat + * that they nicely supplied on request. + * + * Usage examples: + * gpsbabel -i globalsat -f /dev/ttyUSB0 -o gpx,garminextensions -F xxx.gpx + * gpsbabel -i globalsat -f /dev/ttyUSB0 -o gtrnctr,course=0,sport=Running -F xxx.fit + * + */ +#ifndef GLOBALSATSPORT_H_INCLUDED_ +#define GLOBALSATSPORT_H_INCLUDED_ + +#include // for uint32_t, uint8_t, uint16_t, int16_t + +#include // for QString +#include // for QTimeZone +#include // for QVector + +#include "defs.h" +#include "format.h" // for Format +#include "gbfile.h" // for gbfclose, gbfopen, gbfread, gbfwrite, gbfile + + +class GlobalsatSportFormat : public Format +{ +public: + QVector* get_args() override + { + return &globalsat_args; + } + + ff_type get_type() const override + { + return ff_type_serial; + } + + QVector get_cap() const override + { + return { + ff_cap_none, // waypoints + ff_cap_read, // tracks + ff_cap_none, // routes + }; + } + + QString get_encode() const override + { + return CET_CHARSET_ASCII; + } + + int get_fixed_encode() const override + { + return 0; + } + + void rd_init(const QString& fname) override; + void read() override; + void rd_deinit() override; + +private: + /* Types */ + enum globalsat_commands_e { + CommandWhoAmI = 0xBF, + CommandGetSystemInformation = 0x85, + CommandGetSystemConfiguration = 0x86, + + CommandSetSystemConfiguration = 0x96, + CommandSetSystemInformation = 0x98, + CommandGetScreenshot = 0x83, + + CommandGetWaypoints = 0x77, + CommandSendWaypoint = 0x76, + CommandDeleteWaypoints = 0x75, + + CommandSendRoute = 0x93, + CommandDeleteAllRoutes = 0x97, + + CommandGetTrackFileHeaders = 0x78, + CommandGetTrackFileSections = 0x80, + CommandGetNextTrackSection = 0x81, + //CommandReGetLastSection = 0x82, + CommandId_FINISH = 0x8A, + CommandSendTrackStart = 0x90, + CommandSendTrackSection = 0x91, + + HeaderTypeLaps = 0xAA, + HeaderTypeTrackPoints = 0x55, + + ResponseInsufficientMemory = 0x95, + ResponseResendTrackSection = 0x92, + ResponseSendTrackFinish = 0x9A + }; + + struct gh_date { + uint8_t Year; + uint8_t Month; + uint8_t Day; + }; + + struct gh_time { + uint8_t Hour; + uint8_t Minute; + uint8_t Second; + }; + + struct gh_trainheader { + gh_date dateStart; + gh_time timeStart; + uint32_t TotalPoint; //6-9 + uint32_t TotalTime; //10-13 + uint32_t TotalDistance; //14-17 + uint16_t LapCnts; //18-19 + union { + uint32_t Index; + uint32_t StartPt; + } gh_ptrec; //20-23 + union { + uint32_t LapIndex; + uint32_t EndPt; + } gh_laprec; //24-27 + uint8_t DataType; //28 + }; + + struct gh_db_train { + gh_date dateStart; + gh_time timeStart; + uint32_t TotalPoint; //6-9 + uint32_t TotalTime; //10-13 + uint32_t TotalDistance; //14-17 + uint16_t LapCnts; //18-19 + union { + uint32_t Index; + uint32_t StartPt; + } gh_ptrec; //20-23 + union { + uint32_t LapIndex; + uint32_t EndPt; + } gh_laprec; //24-27 + uint8_t MultiSport; //28 on/off + uint16_t Calory; //29-30 + uint32_t MaxSpeed; + uint8_t MaxHeart; + uint8_t AvgHeart; + + uint16_t Ascent; + uint16_t Descent; + + int16_t MinAlti; + int16_t MaxAlti; + uint16_t AvgCadns; + uint16_t BestCadns; + uint16_t AvgPower; + uint16_t MaxPower; + uint8_t Sport1; + uint8_t Sport2; + uint8_t Sport3; + uint8_t Sport4; + uint8_t Sport5; + }; + + struct gh_db_lap { + uint32_t AccruedTime; + uint32_t TotalTime; + uint32_t TotalDistance; + uint16_t Calory; + uint32_t MaxSpeed; + uint8_t MaxHeart; + uint8_t AvgHeart; + int16_t MinAlti; + int16_t MaxAlti; + uint16_t AvgCadns; + uint16_t BestCadns; + uint16_t AvgPower; + uint16_t MaxPower; + uint8_t MultiSportIndex; + uint32_t StartPt; + uint32_t EndPt; + }; + + struct gh_recpoint { + uint32_t Latitude; + uint32_t Longitude; + int16_t Altitude; + uint32_t Speed; + uint8_t HeartRate; + uint32_t IntervalTime; + uint16_t Cadence; + uint16_t PwrCadence; + uint16_t Power; + }; + + /* Member Functions */ + + void serial_init(const char* fname); + void serial_deinit(); + int serial_recv_byte() const; + void serial_write_byte(uint8_t byte) const; + int recv_byte(); + void write_byte(uint8_t byte); + void globalsat_write_package(uint8_t* payload, uint32_t size); + uint8_t* globalsat_read_package(int* out_length, uint8_t* out_DeviceCommand); + void globalsat_send_simple(uint8_t command); + void globalsat_probe_device(); + void waypoint_read(); + void track_read(); + static void route_read(); + + /* Data Members */ + + void* serial_handle{nullptr}; + bool isSizeSwapped{false}; + + char* showlist{nullptr}; // if true show a list instead of download tracks + char* track{nullptr}; // if not 0 only download this track, if 0 download all + + char* opt_dump_file{nullptr}; // dump raw data to this file (optional) + char* opt_input_dump_file{nullptr}; // if true input is from a dump-file instead of serial console + char* opt_timezone{nullptr}; + gbfile* dumpfile{nullptr}; // used for creating bin/RAW datadump files, useful for testing + gbfile* in_file{nullptr}; // used for reading from bin/RAW datadump files, useful for testing + QTimeZone* timezn{nullptr}; + + QVector globalsat_args = { + {"showlist", &showlist, "list tracks", nullptr, ARGTYPE_BOOL, ARG_NOMINMAX, nullptr}, + {"track", &track, "get track", "0", ARGTYPE_INT, ARG_NOMINMAX, nullptr}, + {"dump-file", &opt_dump_file, "Dump raw data to this file", nullptr, ARGTYPE_OUTFILE, ARG_NOMINMAX, nullptr}, + {"input-is-dump-file", &opt_input_dump_file, "Dump raw data to this file", nullptr, ARGTYPE_BOOL, ARG_NOMINMAX, nullptr}, + {"timezone", &opt_timezone, "Time zone ID", nullptr, ARGTYPE_STRING, ARG_NOMINMAX, nullptr}, + }; +}; +#endif // GPX_H_INCLUDED_ diff --git a/subrip.cc b/subrip.cc index 8db5d1568..7e32265aa 100644 --- a/subrip.cc +++ b/subrip.cc @@ -24,10 +24,10 @@ #include // for QDebug #include // for QString #include // for QTime -#include // for QVector #include // for UTC #include "defs.h" +#include "subrip.h" #include "gbfile.h" // for gbfprintf, gbfclose, gbfopen, gbfwrite, gbfile #include "src/core/datetime.h" // for DateTime #include "src/core/logging.h" // for Fatal @@ -35,29 +35,16 @@ #define MYNAME "subrip" -static char* opt_videotime; -static char* opt_gpstime; -static char* opt_gpsdate; -static char* opt_format; -static QDateTime gps_datetime; // Date time corresponding to video video_offset_ms -static QDateTime video_datetime; // Date time corresponding to video time 00:00:00,000. -static int video_offset_ms; -static int stnum; -static gbfile* fout; -static const Waypoint* prevwpp; -static double vspeed; -static double gradient; - /* internal helper functions */ -static QTime -video_time(const QDateTime& dt) +QTime +SubripFormat::video_time(const QDateTime& dt) const { return QTime::fromMSecsSinceStartOfDay(video_datetime.msecsTo(dt)); } -static void -subrip_prevwp_pr(const Waypoint* waypointp) +void +SubripFormat::subrip_prevwp_pr(const Waypoint* waypointp) { static long long deltaoffset; @@ -165,8 +152,8 @@ subrip_prevwp_pr(const Waypoint* waypointp) /* callback functions */ -static void -subrip_trkpt_pr(const Waypoint* waypointp) +void +SubripFormat::subrip_trkpt_pr(const Waypoint* waypointp) { /* * To determine the duration of the subtitle, we need the timestamp of the @@ -206,8 +193,8 @@ subrip_trkpt_pr(const Waypoint* waypointp) /* global callback (exported) functions */ -static void -subrip_wr_init(const QString& fname) +void +SubripFormat::wr_init(const QString& fname) { stnum = 1; prevwpp = nullptr; @@ -250,16 +237,19 @@ subrip_wr_init(const QString& fname) fout = gbfopen(fname, "wb", MYNAME); } -static void -subrip_wr_deinit() +void +SubripFormat::wr_deinit() { gbfclose(fout); } -static void -subrip_write() +void +SubripFormat::write() { - track_disp_all(nullptr, nullptr, subrip_trkpt_pr); + auto subrip_trkpt_pr_lambda = [this](const Waypoint* waypointp)->void { + subrip_trkpt_pr(waypointp); + }; + track_disp_all(nullptr, nullptr, subrip_trkpt_pr_lambda); /* * Due to the necessary hack, one waypoint is still in memory (unless we @@ -269,30 +259,3 @@ subrip_write() subrip_prevwp_pr(nullptr); } } - -/* arguments: definitions of format-specific arguments */ - -static QVector subrip_args = { - {"video_time", &opt_videotime, "Video position for which exact GPS time is known (hhmmss[.sss], default is 00:00:00,000)", nullptr, ARGTYPE_STRING, ARG_NOMINMAX, nullptr }, - {"gps_time", &opt_gpstime, "GPS time at position video_time (hhmmss[.sss], default is first timestamp of track)", nullptr, ARGTYPE_STRING, ARG_NOMINMAX, nullptr }, - {"gps_date", &opt_gpsdate, "GPS date at position video_time (yyyymmdd, default is first timestamp of track)", nullptr, ARGTYPE_STRING, ARG_NOMINMAX, nullptr }, - {"format", &opt_format, "Format for subtitles", "%s km/h %e m\\n%t %l", ARGTYPE_STRING, ARG_NOMINMAX, nullptr }, -}; - -/* manifest: capabilities of this module, pointers to exported functions and others */ - -ff_vecs_t subrip_vecs = { - ff_type_file, - { ff_cap_none, ff_cap_write, ff_cap_none }, // waypoints, track, route; for now, we just do tracks - nullptr, - subrip_wr_init, - nullptr, - subrip_wr_deinit, - nullptr, - subrip_write, - nullptr, - &subrip_args, - CET_CHARSET_ASCII, 0 - , NULL_POS_OPS, - nullptr -}; diff --git a/subrip.h b/subrip.h new file mode 100644 index 000000000..15befa497 --- /dev/null +++ b/subrip.h @@ -0,0 +1,96 @@ +/* + Write points to SubRip subtitle file (for video geotagging) + + Copyright (C) 2010 Michael von Glasow, michael @t vonglasow d.t com + Copyright (C) 2014 Gleb Smirnoff, glebius @t FreeBSD d.t org + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + */ +#ifndef SUBRIP_H_INCLUDED_ +#define SUBRIP_H_INCLUDED_ + +#include // for QDateTime, operator<< +#include // for QString +#include // for QTime +#include // for QVector + +#include "defs.h" +#include "format.h" // for Format +#include "gbfile.h" // for gbfprintf, gbfclose, gbfopen, gbfwrite, gbfile + + +class SubripFormat : public Format +{ +public: + QVector* get_args() override + { + return &subrip_args; + } + + ff_type get_type() const override + { + return ff_type_file; + } + + QVector get_cap() const override + { + return { ff_cap_none, ff_cap_write, ff_cap_none }; // waypoints, track, route; for now, we just do tracks + } + + QString get_encode() const override + { + return CET_CHARSET_ASCII; + } + + int get_fixed_encode() const override + { + return 0; + } + + void wr_init(const QString& fname) override; + void write() override; + void wr_deinit() override; + +private: + /* Member Functions */ + + QTime video_time(const QDateTime& dt) const; + void subrip_prevwp_pr(const Waypoint* waypointp); + void subrip_trkpt_pr(const Waypoint* waypointp); + + /* Data Members */ + + char* opt_videotime{nullptr}; + char* opt_gpstime{nullptr}; + char* opt_gpsdate{nullptr}; + char* opt_format{nullptr}; + QDateTime gps_datetime; // Date time corresponding to video video_offset_ms + QDateTime video_datetime; // Date time corresponding to video time 00:00:00,000. + int video_offset_ms{0}; + int stnum{1}; + gbfile* fout{nullptr}; + const Waypoint* prevwpp{nullptr}; + double vspeed{0.0}; + double gradient{0.0}; + + QVector subrip_args = { + {"video_time", &opt_videotime, "Video position for which exact GPS time is known (hhmmss[.sss], default is 00:00:00,000)", nullptr, ARGTYPE_STRING, ARG_NOMINMAX, nullptr }, + {"gps_time", &opt_gpstime, "GPS time at position video_time (hhmmss[.sss], default is first timestamp of track)", nullptr, ARGTYPE_STRING, ARG_NOMINMAX, nullptr }, + {"gps_date", &opt_gpsdate, "GPS date at position video_time (yyyymmdd, default is first timestamp of track)", nullptr, ARGTYPE_STRING, ARG_NOMINMAX, nullptr }, + {"format", &opt_format, "Format for subtitles", "%s km/h %e m\\n%t %l", ARGTYPE_STRING, ARG_NOMINMAX, nullptr }, + }; +}; +#endif // SUBRIP_H_INCLUDED_ diff --git a/vecs.h b/vecs.h index 5c96ac1d8..7a0d57fa3 100644 --- a/vecs.h +++ b/vecs.h @@ -29,8 +29,10 @@ #include "defs.h" #include "format.h" +#include "energympro.h" #include "geojson.h" #include "ggv_bin.h" +#include "globalsat_sport.h" #include "gpx.h" #include "legacyformat.h" #include "lowranceusr.h" @@ -40,6 +42,7 @@ #include "qstarz_bl_1000.h" #include "random.h" #include "shape.h" +#include "subrip.h" #include "xcsv.h" #include "yahoo.h" @@ -168,14 +171,11 @@ extern ff_vecs_t skytraq_fvecs; extern ff_vecs_t miniHomer_vecs; extern ff_vecs_t jogmap_vecs; extern ff_vecs_t wintec_tes_vecs; -extern ff_vecs_t subrip_vecs; extern ff_vecs_t format_garmin_xt_vecs; extern ff_vecs_t format_fit_vecs; extern ff_vecs_t mapbar_track_vecs; extern ff_vecs_t f90g_track_vecs; extern ff_vecs_t mapfactor_vecs; -extern ff_vecs_t energympro_vecs; -extern ff_vecs_t globalsat_sport_vecs; #endif // MAXIMAL_ENABLED class Vecs @@ -400,17 +400,17 @@ private: LegacyFormat miniHomer_fmt {miniHomer_vecs}; LegacyFormat jogmap_fmt {jogmap_vecs}; LegacyFormat wintec_tes_fmt {wintec_tes_vecs}; - LegacyFormat subrip_fmt {subrip_vecs}; + SubripFormat subrip_fmt; LegacyFormat format_garmin_xt_fmt {format_garmin_xt_vecs}; LegacyFormat format_fit_fmt {format_fit_vecs}; LegacyFormat mapbar_track_fmt {mapbar_track_vecs}; LegacyFormat f90g_track_fmt {f90g_track_vecs}; LegacyFormat mapfactor_fmt {mapfactor_vecs}; - LegacyFormat energympro_fmt {energympro_vecs}; + EnergymproFormat energympro_fmt; MyNavFormat mynav_fmt; GeoJsonFormat geojson_fmt; GgvBinFormat ggv_bin_fmt; - LegacyFormat globalsat_sport_fmt {globalsat_sport_vecs}; + GlobalsatSportFormat globalsat_sport_fmt; QstarzBL1000Format qstarz_bl_1000_fmt; #endif // MAXIMAL_ENABLED -- 2.30.2